package com.caterina.activityManager;
import java.awt.Rectangle;

import com.caterina.components.CFrame;
import controllers.AsyncController;
import controllers.ManagerTask;
import controllers.ManagerTask.TaskType;

public class ActivityManager {
	public ActivityManager(CActivity main,AsyncController controller){
		createControllerThread(controller);
		this.main=main;
		this.main.setActivityManager(this);
	}
	private void createControllerThread(AsyncController controller){
		this.dataController=controller;
		this.dataControllerThr=new Thread(this.dataController);
		this.dataControllerThr.start();
	}
	public CActivity getCurrentActivity(){
		return this.activityFrame.getCurrentActivity();
	}
	public void abortAll(TaskType taskType){
		this.dataController.abortAll(taskType);
	}
	public void putTask(ManagerTask task){
		this.dataController.putTask(task);
	}
	public static Rectangle getFrameBounds(){
		return CFrame.getSafetyBounds();
	}
	public AsyncController getDataController(){
		return this.dataController;
	}
	public void toMain(){
		this.switchActivity(main);
	}
	public void start(){
		activityFrame=new CFrame(main);
		activityFrame.setBounds(ActivityManager.getFrameBounds());
		activityFrame.setVisible(true);
	}
	public void switchActivity(CActivity nextActivity){
		try{
			nextActivity.setActivityManager(this);
			activityFrame.putActivity(nextActivity);
		}catch(Exception ex){
			ex.printStackTrace();
		}
	}

	public void setManagerAt(CActivity activity){
		activity.setActivityManager(this);
	}
	public CFrame getFrame(){
		return activityFrame;
	}
	private Thread dataControllerThr;
	private AsyncController dataController;
	private CFrame activityFrame;
	private CActivity main;
}
